package com.oba.king.datalib.creditcontrol;

import javax.faces.model.DataModel;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;
import com.oba.king.datalib.Customer;

/**
 * 
 * @author 大饼
 * 信用控制
 */
public class CreditControlBean extends BaseBean<CreditControl, CreditControlService>{
 
	private DBDataModel creditControlData=DBDataModel.create();
	
	private CreditControl creditControl;
	
	private boolean showCreditControl;
	
	
	public void doAddRow(){
		creditControl=new CreditControl();
		creditControl.setNewBo(true);
		showCreditControl=true;
	}
	
	public void doDeleteRow() {
		if(creditControlData.isRowAvailable()) {
			creditControl = (CreditControl) creditControlData.getRowData();
			getService().del(creditControl);
			doFind();
		}
	}
	
	public void doEditRow() {
		if(creditControlData.isRowAvailable()) {
			creditControl = (CreditControl) creditControlData.getRowData();
			showCreditControl = true;
			doFind();
		}
	}
	
	public void closeShowEdit() {
		showCreditControl = false;
	}
	
	public void doSaveRow() {

		getService().save(creditControl);
		showCreditControl = false;
		doFind();
	}
	
	
	@Override
	public String doFind() {
		creditControlData.find(getService().getDao().findAll());
		return null;
	}

	@Override
	public void init() {
		creditControlData.find(getService().getDao().findAll());	
		
		creditControl=new CreditControl();
		showCreditControl=false;
	}

	public DBDataModel getCreditControlData() {
		return creditControlData;
	}

	public void setCreditControlData(DBDataModel creditControlData) {
		this.creditControlData = creditControlData;
	}

	public CreditControl getCreditControl() {
		return creditControl;
	}

	public void setCreditControl(CreditControl creditControl) {
		this.creditControl = creditControl;
	}

	public boolean isShowCreditControl() {
		return showCreditControl;
	}

	public void setShowCreditControl(boolean showCreditControl) {
		this.showCreditControl = showCreditControl;
	}

}
